#!/usr/bin/env python

def colorize(txt, col):
    """Return colorized text"""
    cols = { 'red':1, 'green':2, 'yellow':3, 'blue':4, 'magenta':5, 'cyan':6}
    initcode = '\033[;3'
    endcode  = '\033[0m'
    if type(col) == type(1):
        return initcode + str(col) + 'm' + txt + endcode
    try: return initcode + str(cols[col]) + 'm' + txt + endcode
    except: return txt

def main():
    import sys
    if len(sys.argv) > 2:
	try:
	    color = int(sys.argv[1])
	except ValueError:
	    color = sys.argv[1]
	
	text = sys.argv[2]
	if len(sys.argv[2:]) > 1:
	    text = " ".join(sys.argv[2:])

	print colorize(text, color)

    else:
	for col in range(1,7):
	    print col, colorize("hallo", col), repr(colorize("hallo", col))

if __name__ == "__main__":
    main()
